package cn.lanchengkeji.datafillingsystem.controller;




import cn.lanchengkeji.datafillingsystem.common.DictConst;
import cn.lanchengkeji.datafillingsystem.common.ResponseBean;
import cn.lanchengkeji.datafillingsystem.common.StatusCode;
import cn.lanchengkeji.datafillingsystem.service.IDictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author yuhao
 * @since 2018-12-06
 */
@Api(hidden = false, tags = {"字典表 前端控制器"})
@RestController
@RequestMapping("/dictionary")
public class DictionaryController extends BaseController {

    // 日志
    private static Logger logger = LoggerFactory.getLogger(DictionaryController.class);

    @Resource
    private IDictionaryService iDictionaryService;

    /**
     * 查看所有角色：登陆后才能操作
     *
     * @return
     * @throws Exception
     */
    @ApiOperation(hidden = false, value = "查看所有角色", notes = "登陆才能操作")
    @ApiImplicitParams({
    })
    @RequiresAuthentication
    @RequiresPermissions("operation:view")
    @RequestMapping(value = "/selectSysRoles", method = RequestMethod.POST)
    public ResponseBean selectSysRoles() throws Exception {

        // 获取登陆系统用户名，存入日志
        Object obj = SecurityUtils.getSubject().getPrincipal();
        logger.debug((String) obj);

        // 获取全部角色
        return new ResponseBean(StatusCode.OK, iDictionaryService.getListByGroup(DictConst.GROUP_SYS_ROLE));
    }

    /**
     * 查看所有权限：登陆后才能操作
     *
     * @return
     * @throws Exception
     */
    @ApiOperation(hidden = false, value = "查看所有权限", notes = "登陆才能操作")
    @ApiImplicitParams({
    })
    @RequiresAuthentication
    @RequiresPermissions("operation:view")
    @RequestMapping(value = "/selectSysOperation", method = RequestMethod.POST)
    public ResponseBean selectSysOperation() throws Exception {

        // 获取登陆系统用户名，存入日志
        Object obj = SecurityUtils.getSubject().getPrincipal();
        logger.debug((String) obj);

        // 获取全部角色
        return new ResponseBean(StatusCode.OK, iDictionaryService.getListByGroup(DictConst.GROUP_SYS_OPERATION));
    }
}
